
<!DOCTYPE html>
<html>

	<head>
	<title>CAIJL's Blog</title>
	<meta charset="utf-8"/>
	<link rel="stylesheet" href="/font-awesome-4.7.0/css/font-awesome.min.css">

	<link rel="stylesheet" href="/bootstrap-3.3.7/css/bootstrap.min.css">
	<script src="/jquery-2.1.1/jquery.min.js"></script>
	<script src="/bootstrap-3.3.7/js/bootstrap.min.js"></script>

	<link rel="stylesheet" href="/css/bootstrap-slider.min.css">
	<script src="/js/bootstrap-slider.min.js"></script>
	
	<link rel="stylesheet" href="/css/main.css">
	<script src="/js/main.js"></script>
	
	<link rel="stylesheet" href="/css/cursor.css">
	<script src="/js/cursor.js"></script>
	
	
	<link rel="stylesheet" href="/css/code.css">
	<!--link rel="stylesheet" href="/css/markdown.css"-->
	
	<link rel="stylesheet" href="/css/head.css">

	<script src="/js/window.js"></script>
	<script src='//unpkg.com/valine/dist/Valine.min.js'></script>
	</head>
<body>

	<link rel="stylesheet" href="/katex/katex.min.css" crossorigin="anonymous">
	<script src="/katex/katex.min.js" crossorigin="anonymous"></script>
	<script src="/katex/contrib/mathtex-script-type.min.js" defer></script>
	<script defer src="/katex/contrib/auto-render.min.js"crossorigin="anonymous"
	    onload="renderMathInElement(document.body);"></script>
	<script>document.addEventListener("DOMContentLoaded", function() {renderMathInElement(document.body,{"delimiters":[{left: "$", right: "$", display: false}]});});</script>
	<nav class="navbar navbar-default header card" role="navigation" style="width: 100%;">
	<div class="container-fluid"> 
	<div class="navbar-header">
		<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target="#example-navbar-collapse">
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
		</button>
		<a class="navbar-brand" href="/"><span><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold">C</mi><mi mathvariant="bold">A</mi><mi mathvariant="bold">I</mi><mi mathvariant="bold">J</mi><msup><mi mathvariant="bold">L</mi><mo mathvariant="bold" lspace="0em" rspace="0em">′</mo></msup><mi mathvariant="bold">s</mi><mi mathvariant="bold">B</mi><mi mathvariant="bold">L</mi><mi mathvariant="bold">O</mi><mi mathvariant="bold">G</mi></mrow><annotation encoding="application/x-tex">\mathbf{CAIJL'sBLOG}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height: 0.751892em; vertical-align: 0em;"></span><span class="mord"><span class="mord mathbf">C</span><span class="mord mathbf">A</span><span class="mord mathbf">I</span><span class="mord mathbf">J</span><span class="mord"><span class="mord mathbf">L</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height: 0.751892em;"><span class="" style="top: -3.063em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathbf mtight">′</span></span></span></span></span></span></span></span></span><span class="mord mathbf">s</span><span class="mord mathbf">B</span><span class="mord mathbf">L</span><span class="mord mathbf">O</span><span class="mord mathbf">G</span></span></span></span></span></span></a>
	</div>
	<div class="collapse navbar-collapse" id="example-navbar-collapse">
		<ul class="nav navbar-nav" style="background-color:#fcfcfc">
			<li><a href="/"><i class="menu-item-icon fa fa-fw fa-home"></i>首页</a></li>
			<li><a href="/archives/"><i class="menu-item-icon fa fa-fw fa-archive"></i>文章</a></li>
			<li><a href="/tags/"><i class="menu-item-icon fa fa-fw fa-tags"></i>标签</a></li>
			<li><a href="/settings/"><i class="menu-item-icon fa fa-fw fa-cogs"></i>设置</a></li>
			<!--li><a href="/about/"><i class="menu-item-icon fa fa-fw fa-user"></i>关于</a></li-->
			<li><a href="/games/"><i class="menu-item-icon fa fa-fw fa-gamepad"></i>其它</a></li>
			

		</ul>
	</div>
	</div>
	</nav>
<div class="container">
	<div style="height: 60px;"></div>
	<div class="row" >
		<div class="col-md-8">
			<div class="panel panel-default card" style="padding: 10px;position: relative;">
                <img src='/img/bg/28.png' style="width:100%"/>
				<span style="position: absolute;left:15px;bottom:15px;width:90%;"><font class="view-text" style="color:#fcfcfc;font-size:25px">FWT 学习笔记</font><br><a href="/tags/2021/" class="tag"><span  style="background-color: rgb(52, 152, 219);">2021</span></a>&nbsp;<a href="/tags/笔记/" class="tag"><span  style="background-color: rgb(82, 196, 26);">笔记</span></a></span>
			</div>
			<div class="panel panel-default card" style="padding: 10px;" id="main">
                <h1 id="largelceil-mathrmfwtrfloortext">
<script type="math/tex">\large{\lceil \mathrm{FWT}\rfloor}\text{学习笔记}</script>
</h1>
<p>
<script type="math/tex">\lceil \mathrm{FWT}\rfloor</script> 解决的是一类 <strong>下标位运算卷积</strong>，通过一种 <strong>可逆</strong> 的变换来求解下面这样的问题：</p>
<p>
<script type="math/tex; mode=display">\boxed{C[i]=\sum_{j\circ k=i}A[j]\times B[k]}</script>
</p>
<p>其中 <script type="math/tex">\circ</script> 是 <script type="math/tex">\&,|,\oplus</script> 中的一种。</p>
<h2 id="lceil-mathrmfwt-mathcalor-rfloor">
<script type="math/tex">\lceil \mathrm{FWT} - \mathcal{OR} \rfloor</script>
</h2>
<p>即：
<script type="math/tex; mode=display">\boxed{C[i]=\sum_{j|k=i}A[j]\times B[k]}</script>
</p>
<p>来考虑变换 <script type="math/tex">F</script>，记为 <script type="math/tex">T'=F(T)</script>，使得 <script type="math/tex">T'[i]=\sum_{j|i=i}T[i]</script>，也就是<strong>下标的所有子集</strong>的和。</p>
<p>不难有 <script type="math/tex">j|i=i,k|i=i\Longleftrightarrow (j|k)|i=i</script>，也可以从集合解释。</p>
<p>那么：
<script type="math/tex; mode=display">
\begin{aligned}
&A'[i]\times B'[i]\\
=&\left(\sum_{j|i=i}A[j]\right)\left(\sum_{k|i=i}B[k]\right)\\
=&\sum_{j|i=i}\sum_{k|i=i}A[j]\times B[k]\\
=&\sum_{(j|k)|i=i}A[j]\times B[k]\\
=&C'[i]
\end{aligned}
</script>
这个性质就和 <script type="math/tex">\lceil \mathrm{FFT}\rfloor</script> 比较类似了，相当于把点值相乘。</p>
<p>考虑快速计算变换 <script type="math/tex">F</script>，很明显如果计算完了 <script type="math/tex">[1,mid],[mid+1,n]</script>，那么把两者拼接起来新的数组，对于 <script type="math/tex">[1,mid]</script> 最高位是 <script type="math/tex">0</script> 不发生变化，<script type="math/tex">[mid+1,n]</script> 最高位是 <script type="math/tex">1</script> 因此要算上 <script type="math/tex">[1,mid]</script> 的贡献，最终得到：</p>
<p>
<script type="math/tex; mode=display">F(A)=\mathrm{merge}(F(A[1\ldots mid]),F(A[1\ldots mid])+F(A[mid+1\ldots n]))</script>
</p>
<p>那么再来考虑逆运算，假装先对 <script type="math/tex">[1,mid],[mid+1,n]</script> 求一遍逆，那么现在 <script type="math/tex">[1,mid]</script> 对 <script type="math/tex">[mid+1,n]</script> 的贡献还没有消除，因此逆变换就是：</p>
<p>
<script type="math/tex; mode=display">A=\mathrm{merge}(A[1\ldots mid],A[mid+1\ldots n]-A[1\ldots mid])</script>
</p>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="kt">void</span> <span class="nf">OR</span><span class="p">(</span><span class="n">mint</span> <span class="o">*</span><span class="n">f</span><span class="p">,</span><span class="n">mint</span> <span class="n">op</span><span class="o">=</span><span class="mi">1</span><span class="p">){</span>
<span class="linenos" data-linenos="2 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">o</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span><span class="n">k</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">o</span><span class="o">&lt;=</span><span class="n">n</span><span class="p">;</span><span class="n">o</span><span class="o">&lt;&lt;=</span><span class="mi">1</span><span class="p">,</span><span class="n">k</span><span class="o">&lt;&lt;=</span><span class="mi">1</span><span class="p">)</span>
<span class="linenos" data-linenos="3 "></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">+=</span><span class="n">o</span><span class="p">)</span>
<span class="linenos" data-linenos="4 "></span>            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos="5 "></span>                <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="o">+</span><span class="n">k</span><span class="p">]</span><span class="o">+=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="p">]</span><span class="o">*</span><span class="n">op</span><span class="p">;</span>
<span class="linenos" data-linenos="6 "></span><span class="p">}</span>
</code></pre></div>
<h2 id="lceil-mathrmfwt-mathcaland-rfloor">
<script type="math/tex">\lceil \mathrm{FWT} - \mathcal{AND} \rfloor</script>
</h2>
<p>
<script type="math/tex; mode=display">\boxed{C[i]=\sum_{j\& k=i}A[j]\times B[k]}</script>
与 和 或 其实性质很相似。类似地，可以构造变换 <script type="math/tex">F</script> 满足：
<script type="math/tex; mode=display">T'[i]=\sum_{j\&i=i}T[i]</script>
不难得到：
<script type="math/tex; mode=display">A'[i]\times B'[i]=C'[i]</script>
<script type="math/tex; mode=display">F(A)=\mathrm{merge}(F(A[1\ldots mid])+F(A[mid+1\ldots n],F(A[mid+1\ldots n]))</script>
<script type="math/tex; mode=display">A=\mathrm{merge}(A[1\ldots mid]-A[mid+1,n],A[mid+1,n])</script>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="kt">void</span> <span class="nf">AND</span><span class="p">(</span><span class="n">mint</span> <span class="o">*</span><span class="n">f</span><span class="p">,</span><span class="n">mint</span> <span class="n">op</span><span class="o">=</span><span class="mi">1</span><span class="p">){</span>
<span class="linenos" data-linenos="2 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">o</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span><span class="n">k</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">o</span><span class="o">&lt;=</span><span class="n">n</span><span class="p">;</span><span class="n">o</span><span class="o">&lt;&lt;=</span><span class="mi">1</span><span class="p">,</span><span class="n">k</span><span class="o">&lt;&lt;=</span><span class="mi">1</span><span class="p">)</span>
<span class="linenos" data-linenos="3 "></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">+=</span><span class="n">o</span><span class="p">)</span>
<span class="linenos" data-linenos="4 "></span>            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos="5 "></span>                <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="p">]</span><span class="o">+=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="o">+</span><span class="n">k</span><span class="p">]</span><span class="o">*</span><span class="n">op</span><span class="p">;</span>
<span class="linenos" data-linenos="6 "></span><span class="p">}</span>
</code></pre></div></p>
<h2 id="lceil-mathrmfwt-mathcalxor-rfloor">
<script type="math/tex">\lceil \mathrm{FWT} - \mathcal{XOR} \rfloor</script>
</h2>
<p>
<script type="math/tex; mode=display">\boxed{C[i]=\sum_{j\oplus k=i}A[j]\times B[k]}</script>
亦或 与前两种相比更加麻烦。</p>
<p>设 <script type="math/tex">a \bullet b=\mathrm{popcount}(a\&b)\bmod 2</script> ，那么就有：
<script type="math/tex; mode=display">(i\bullet j)\oplus (i\bullet k)=i\bullet(j\oplus k)</script>
讨论一下应该是对的。</p>
<p>于是构造变换 <script type="math/tex">F</script> 使得：
<script type="math/tex; mode=display">T'[i]=\sum_{i\bullet j=0}T[j]-\sum_{i\bullet j=1}T[j]</script>
那么来验证一波：
<script type="math/tex; mode=display">
\begin{aligned}
&A'[i]\times B'[i]\\
=&\left(\sum_{i\bullet j=0}A[j]-\sum_{i\bullet j=1}A[j]\right)\times\left(\sum_{i\bullet k=0}B[k]-\sum_{i\bullet k=1}B[k]\right)\\
=&\left(\sum_{i\bullet j=0}A[j]\right)\times\left(\sum_{i\bullet k=0}B[k]\right)+\left(\sum_{i\bullet j=1}A[j]\right)\times\left(\sum_{i\bullet k=1}B[k]\right)\\
&-\left(\sum_{i\bullet j=0}A[j]\right)\times\left(\sum_{i\bullet k=1}B[k]\right)-\left(\sum_{i\bullet j=1}A[j]\right)\times\left(\sum_{i\bullet k=0}B[k]\right)\\
=&\sum_{i\bullet (j\oplus k)=0}A[j]\times B[k]-\sum_{i\bullet(j\oplus k)=1}A[j]\times B[k]\\
=&C'[i]
\end{aligned}
</script>
于是乎：
<script type="math/tex; mode=display">F(A)=\mathrm{merge}(F(A[1,mid])+F(A[mid+1,n]),F(A[1,mid])-F(A[mid+1,n]))</script>
<script type="math/tex; mode=display">A=\mathrm{merge}(\frac{A[1,mid]+A[mid+1,n]}2,\frac{A[1,mid]-A[mid+1,n]}2)</script>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="kt">void</span> <span class="nf">XOR</span><span class="p">(</span><span class="n">mint</span> <span class="o">*</span><span class="n">f</span><span class="p">,</span><span class="n">mint</span> <span class="n">op</span><span class="o">=</span><span class="mi">1</span><span class="p">){</span>
<span class="linenos" data-linenos="2 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">o</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span><span class="n">k</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">o</span><span class="o">&lt;=</span><span class="n">n</span><span class="p">;</span><span class="n">o</span><span class="o">&lt;&lt;=</span><span class="mi">1</span><span class="p">,</span><span class="n">k</span><span class="o">&lt;&lt;=</span><span class="mi">1</span><span class="p">)</span>
<span class="linenos" data-linenos="3 "></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">+=</span><span class="n">o</span><span class="p">)</span>
<span class="linenos" data-linenos="4 "></span>            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos="5 "></span>                <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="p">]</span><span class="o">+=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="o">+</span><span class="n">k</span><span class="p">],</span>
<span class="linenos" data-linenos="6 "></span>                <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="o">+</span><span class="n">k</span><span class="p">]</span><span class="o">=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="p">]</span><span class="o">-</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="o">+</span><span class="n">k</span><span class="p">]</span><span class="o">-</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="o">+</span><span class="n">k</span><span class="p">],</span>
<span class="linenos" data-linenos="7 "></span>                <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="p">]</span><span class="o">*=</span><span class="n">op</span><span class="p">,</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="o">+</span><span class="n">k</span><span class="p">]</span><span class="o">*=</span><span class="n">op</span><span class="p">;</span>
<span class="linenos" data-linenos="8 "></span><span class="p">}</span>
</code></pre></div></p>
			</div>
			<div class="panel panel-default card" style="padding: 10px;height: 50px;font-size: 20px;">
				<a style="float: left;" href="\article\SP5902.html"><i class="fa fa-angle-double-left"></i></a><a style="float: right;" href="\article\CF1513F.html"><i class="fa fa-angle-double-right"></i></a>
			</div>
			<div class="panel panel-default card" style="padding: 10px;font-size: 20px;" id="vcomments">
				
			</div>
			<script>
				new Valine({
					el: '#vcomments',
					appId: 'PAlFUPg0pQVTFTEo8gCB4BCf-gzGzoHsz',
					appKey: 'U38ejnLUiizJ6vLyp6ql4hRq',
					path: window.location.pathname
				})
			</script>
		</div>
		<div class="col-md-3">
				<div class="panel panel-default card">
				<div class="panel-heading">
					<h3 class="panel-title">
						<i class="fa fa-info"></i>&emsp;
						<strong>文章信息</strong>
					</h3>
				</div>
                <div style="margin: 10px;">
                    <div style="margin-top: 8px;display: flex;"> 
    <span style="flex: 1 0 auto;margin-right: 6px;">标题</span>
    <span><font style="font-weight: bold">FWT 学习笔记</font></span>
	</div><div style="margin-top: 8px;display: flex;"> 
    <span style="flex: 1 0 auto;margin-right: 6px;">日期</span>
    <span>2021-05-23 09:47:13</span>
	</div>
                </div>
				</div>
				<div class="panel panel-default card">
				<div class="panel-heading">
					<h3 class="panel-title">
						<i class="fa fa-tag"></i>&emsp;
						<strong>标签</strong>
					</h3>
				</div>
				<div style="margin: 10px;">
					<a href="/tags/2021/" class="tag"><span  style="background-color: rgb(52, 152, 219);">2021</span></a>&nbsp;<a href="/tags/笔记/" class="tag"><span  style="background-color: rgb(82, 196, 26);">笔记</span></a>
				</div>
				</div>
				
			<div class="panel panel-default card">
					<div class="panel-heading">
						<h3 class="panel-title">
							<i class="fa fa-user-circle-o"></i>&emsp;
							<strong>caijicjl</strong>
						</h3>
					</div>
					<div style="width: 60%;display: inline-block;padding-top: 10px;">
						<ul class="propertyLinks" style="list-style-type: none;">
							<li>
								<img style="vertical-align:middle;position:relative;top:-2px" src="/img/rating-16x16.png">
								Rating:&nbsp;
								<span style="font-weight:bold;color: gray ">312</span>
							</li>
							<li>
								<img style="vertical-align:middle;position:relative;top:-2px" src="/img/star_blue_16.png">
								Contribution:&nbsp;
								<span style="color:gray;font-weight:bold;">0</span>
							</li>
						</ul>
						<ul class="nav-links">
							<li><a href="/settings/">Settings</a></li>
							<li><a href="/archives/">Blog</a></li>
							<li><a href="/teams">Teams</a></li>
							<li><a href="/submissions/dingdingsb">Submissions</a></li>
							<li><a href="/usertalk">Talks</a></li>
							<li><a href="/contests/with/dingdingsb">Contests</a></li>
						</ul>
					</div>
					<div style="display:inline-block;vertical-align: top;margin: 10px;text-align: center;">
						<div style="height:50px;width:50px"><img src="/img/avatar.png"/></div>
						<div><a href="https://www.luogu.com.cn/user/174304" style="font-weight:bold;color:gray">caijicjl</a></div>
					</div>
				</div>
		<div class="panel panel-default card">
				<div class="panel-heading">
					<h3 class="panel-title">
						<i class="fa fa-external-link"></i>&emsp;
						<strong>画中画</strong>
					</h3>
				</div>
				<div style="width:100%;margin:10px">
				<input type="text" id="url"/>
				<input value="创建" type="button" onclick="creat('kk')" /> 
				</div>
		</div>
		<script src="/js/hitokoto.js"></script>
							

				
				<span id="kk"></span>
				<div  id="myScrollspy" class="card" style="width: 100%;"  data-spy="affix">
					<script src="/js/make_toc.js"></script>
				</div>
		</div>
	</div>
 </div>
</body>
</html>
